# -*- coding: utf-8 -*-
# @Time    : 2020/3/9 10:23
# @Author  : Weymouth
# @Email   : 261229090@qq.com
# @File    : logging_module.py
# @Software: PyCharm
# ---------------------------------------------------

import logging

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

#创建一个handler，用于写入日志文件
fh = logging.FileHandler('test.log')

#再创建一个handler，用于输出到控制台
ch = logging.StreamHandler()


#定义Formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

#为Handler添加Formatter
fh.setFormatter(formatter)
ch.setFormatter(formatter)

#可以通过addHandler()方法为Logger添加多个Handler
logger.addHandler(fh)
logger.addHandler(ch)

logger.debug('debug message')
logger.info('info message')
logger.warning('warning message')
logger.error('error message')
logger.critical('critical message')